﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;
using System.Configuration;

namespace SortFile
{
    class Program
    {
        private static readonly string _InputFile = "Input_File";
        static void Main(string[] args)
        {
            //var file = @"D:\RanD\SortFile\SortFile\Inputs\Product_src1.csv"; 
            var file = ConfigurationManager.AppSettings[_InputFile];

            var fileHandler = new LargeFile();
            fileHandler.OnProgress += FileHandler_OnProgress;
            fileHandler.Sort(file);
            Console.ReadKey();
        }

        private static void FileHandler_OnProgress(EventInfo info)
        {
            switch (info.Stage)
            {
                case SortStage.ssStart:
                    Console.WriteLine("+++++++++++++++++++++++++++++++++++++++++++++++++++++++");
                    Console.WriteLine(info.Message);
                    break;
                case SortStage.ssMakeChunk:
                    Console.WriteLine(info.Message);
                    break;
                case SortStage.ssCloseChunk:
                    Console.WriteLine("---------------------------------------------------");
                    break;
                case SortStage.ssWriteLine:
                    Console.WriteLine(info.Message);
                    break;
                case SortStage.ssFinishedSplit:
                    Console.WriteLine(info.Message);
                    Console.WriteLine("Finished Splitting files : {0} ms", info.ElapsedTime);
                    break;
                case SortStage.ssStartSort:
                    Console.WriteLine("+++++++++++++++++++++++++++++++++++++++++++++++++++++++");
                    Console.WriteLine("Start Sorting the split file chunks..");
                    break;
                case SortStage.ssSorting:
                    Console.WriteLine(info.Message);
                    break;
                case SortStage.ssSorted:
                    Console.WriteLine("Finished Sorting files : {0} ms", info.ElapsedTime);
                    break;
                case SortStage.ssStartMerge:
                    Console.WriteLine("+++++++++++++++++++++++++++++++++++++++++++++++++++++++");
                    Console.WriteLine("Start Merge Sorting the chunks..");
                    break;
                case SortStage.ssMerging:
                    Console.WriteLine(info.Message);
                    break;
                case SortStage.ssMerged:
                    Console.WriteLine("Finished Merge Sorting the files : {0} ms", info.ElapsedTime);
                    break;
            }
        }
    }
}
